Skip to content

Support IPv6 in host config #2595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2023
Merged

Support IPv6 in host config #2595

merged 1 commit into from
Sep 5, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Sep 4, 2023

Fix #2528

Response from MongoDB AI chat (internal experimentation):

To connect to an IPv6 server with the MongoDB PHP driver, you can specify the IPv6 address or hostname in the connection string. For example, if your server is listening on the IPv6 address 2001:0db8:85a3:0000:0000:8a2e:0370:7334 and port 27017, you can use the following connection string:

mongodb://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:27017

Note that the IPv6 address must be enclosed in square brackets. For more information on connection strings, please refer to the "Connection String URI Format" section of the MongoDB PHP driver documentation in my knowledge.

@GromNaN GromNaN merged commit 51bbdf7 into mongodb:master Sep 5, 2023
@GromNaN GromNaN deleted the ipv6 branch September 5, 2023 07:31
$host = $host.':'.$config['port'];
// ipv6
if (filter_var($host, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
$host = '['.$host.']';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to check that libmongoc supports this notation, and it is handled in _mongoc_host_list_from_string_with_err.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did test before doing the PR 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to parse ipv6 host or dsn
3 participants